package com.example.web;
import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Employee extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String uname=request.getParameter("username");
String upass=request.getParameter("password");
HttpSession session=request.getSession();
Authentication auth=new Authentication();
boolean log=auth.authenticate(uname.trim(),upass);
if(log==true)
{ 
	String role=auth.chkrole(uname);
	if(role.equals("user"))
	{
	session.setAttribute("uid",uname);
	//RequestDispatcher rd=request.getRequestDispatcher("home.jsp");
	session.setAttribute("rol","user");
	//rd.forward(request,response);
	response.sendRedirect("home.jsp");
	}
	else{
	session.setAttribute("uid",uname);
	//RequestDispatcher rd=request.getRequestDispatcher("adminhome.jsp");
	session.setAttribute("rol","admin");
	//rd.forward(request,response);
	response.sendRedirect("adminhome.jsp");
	}
	
}
else{

RequestDispatcher rd=request.getRequestDispatcher("form.jsp");
request.setAttribute("ermsg","The username or password you entered is incorrect.");
rd.forward(request,response);
//response.sendRedirect("form.jsp?msg="+msg);
}

}
}